const path = require("path");

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1724343219908_732";

  config.cluster = {
    listen: {
      path: "",
      port: 7001,
      hostname: "0.0.0.0",
    },
  };

  // socket.io
  config.io = {
    init: {
      wsEngine: "ws", // ws 引擎
    },
    cors: {
      // 这里配置 Socket.io 的 CORS 选项
      origin: "*", // 允许所有跨域请求，或者指定具体的域名
      methods: ["GET", "POST"],
    },
    namespace: {
      "/agent": {
        connectionMiddleware: [
          // 'auth', 连接中间件
          "agent",
        ],
        packetMiddleware: [],
      },
    },
  };

  config.redis = {
    client: {
      port: 6379,
      host: "66.112.211.55",
      password: "",
      db: 0, // Redis 数据库索引
    },
  };

  // 配置了视图引擎的绝对路径
  config.view = {
    defaultViewEngine: "nunjucks",
    root: path.join(appInfo.baseDir, "app/views"),
    mapping: {
      // 这里可以是.nj/.tpl/.html等文件后缀
      // '.nj': 'nunjucks',
      // '.tpl': 'nunjucks',
      ".html": "nunjucks",
    },
  };

  // add your middleware config here
  config.middleware = ['one']; // 跟中间件文件名保持一致

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
